<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/17 0017
 * Time: 下午 2:05
 */
namespace app\auth\validate;
use think\Db;
use think\Validate;

class ValidateFun extends Validate{
    public function __construct(array $rules = [], array $message = [], array $field = [])
    {
        parent::__construct($rules, $message, $field);
    }
    #验证用户名是否存在,存在，返回false
    public function checkUsername($v=''){
        $info = Db::name('member')->where(['del'=>1,'username'=>$v])->find();
        if ($info){
            return false;
        }else{
            return true;
        }
    }

    #验证参数是否存在
    public function checkUserId($v=''){
        $info = Db::name('member')->where(['id'=>$v,'del'=>1])->find();
        if ($info){
            return true;
        }else{
            return false;
        }
    }

    #验证角色是否存在
    public function checkRoleId($v=''){
        $info = Db::name('role')->where(['role_id'=>$v,'del'=>1])->find();
        if ($info){
            return true;
        }else{
            return false;
        }
    }
    #验证角色名称是否存在
    public function checkRoleName($v,$b,$data=[]){
        $info = Db::name('role')->where('del=1 and role_id!='.$data['role_id'].' and role_name="'.$data['role_name'].'"')->find();
        if ($info){
            return false;
        }else{
            return true;
        }
    }

    #验证权限是否存在
    public function checkAuthId($v=''){
        $info = Db::name('auth')->where(['auth_id'=>$v,'del'=>1])->find();
        if ($info){
            return true;
        }else{
            return false;
        }
    }
    #验证权限名称是否存在
    public function checkAuthName($v=''){
        $info = Db::name('auth')->where(['auth_name'=>$v,'del'=>1])->find();
        if ($info){
            return false;
        }else{
            return true;
        }
    }
#验证权限名称是否存在
    public function checkAuthNameN($v,$a,$data=''){
        $info = Db::name('auth')->where('del=1 and auth_id!='.$data['auth_id'].' and auth_name="'.$data['auth_name'].'"')->find();
        if ($info){
            return false;
        }else{
            return true;
        }
    }

}